package com.w3c.pragmatic.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

@Getter
@AllArgsConstructor
public enum RandomEnum {
  SCALE_2(2,"%02d", 100),
  SCALE_3(3,"%03d", 1000),
  SCALE_4(4,"%04d", 10000),
  SCALE_5(5,"%05d", 100000),
  SCALE_6(6,"%06d", 1000000),
  SCALE_7(7,"%07d", 10000000),
  SCALE_8(8,"%08d", 100000000),
  SCALE_9(9,"%09d", 1000000000),
  OTHER(2,"%02d", 100);

  // 保留位数
  private final int scale;
  // 保留位数(正则)
  private final String scaleFormat;
  // 随机数范围
  private final int randomRange;

  /**
   * 通过位数长度 获取枚举
   *
   * @param scale 操作类型
   * @return 返回枚举对象
   */
  public static RandomEnum getEnumByType(int scale) {
    return Stream.of(values()).filter(e -> e.scale == scale).findFirst().orElse(RandomEnum.OTHER);
  }
}
